var app = getApp();
var WxParse = require('../../../lib/wxParse/wxParse.js');
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    id: 0,
    itemId: 0,
    time: 30 * 60 * 60 * 1000,
    purchase: {},
    purchasesStr: '',
    imgs: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;

    that.setData({
      id: options.id,
      itemId: options.itemId,
      purchasesStr: wx.getStorageSync('purchasesStr')
    });

    util.request(api.PurchaseDetail, {
      id: that.data.id,
      itemId: that.data.itemId
    }).then(function (res) {
      if (res.errno === 0) {
        // console.log(res.data)
        let purchase = res.data.purchase;
        purchase.publishDt = util.formatTime2(new Date(purchase.publishDt), "Y/M/D");
        purchase.supplyPrice = util.toDecimal(purchase.supplyPrice);
        let herbListImage = purchase.herbListImage;
        let imgs = '';
        if (herbListImage) {
          imgs = herbListImage.split(',')
        }

        that.setData({
          purchase: purchase,
          imgs: imgs
        });
      }
    });
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  quote: function () {
    wx.setStorageSync('purchaseListStr', this.data.purchasesStr);
    wx.navigateTo({
      url: `/pages/quote/quote`
    })
  },
})